<!--
 * @Author       : cx
 * @Date         : 
 * @Description  : 查看货架信息
 * @ Love and Peace





 *
-->




<template>
  <div>
    <a-modal
      title="货架信息"
      :visible="goodsShelvesTag"
      @ok="handleOk"
      width="70%"
      @cancel="handleCancel"
    >
      <a-table
        :columns="columns"
        :data-source="dataSource"
        :row-selection="{
          selectedRowKeys: orderSelectedRowKeys,
          onChange: orderSelectChange,
        }"
      >
      </a-table>
    </a-modal>
  </div>
</template>

<script>
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口
const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
  },
  {
    title: "货架编码",
    dataIndex: "inOutShelf",
    key: "inOutShelf",
  },
  {
    title: "入库时间",
    dataIndex: "storageDate",
    key: "storageDate",
  },
];
export default {
  props: {
    // goodsShelvesTag 用来显示 弹窗是否打开
    goodsShelvesTag: {
      type: Boolean,
    },
    tableKey: {
      type: Number,
    },
    // 仓库Id 用仓库 Id 查询货架信息
    position: {
      type: [String,Number],
    },
  },

  mounted() {},

  watch: {},

  data() {
    return {
      columns,
      dataSource: [],
      orderSelectedRowKeys: [],
      goodsShelvesList: [], // 物品货架列表
    };
  },

  methods: {
    // 货架编号选择
    orderSelectChange(selectedRowKeys, selectedRows) {
      this.orderSelectedRowKeys = selectedRowKeys;

      console.log("选中的所有项为", selectedRows);
      this.goodsShelvesList = selectedRows;
    },

    // 获取货架信息
    getGoodShelveInfo() {
      this.dataSource = [];

      this.dataSource.push();

      comHttp
        .queryStorageShelvesList("?position=" + this.position)
        .then((res) => {
          console.log("根据仓库查到的货架信息为:::::", res);

          for (let i = 0; i < res.result.length; i++) {
            let data = {
              key: i + 1,
              inOutShelf: res.result[i].shelfNo,
              storageDate: res.result[i].storageDate,
            };
            this.dataSource.push(data);
          }

          console.log(this.dataSource);
        });
    },

    handleOk() {
      this.$emit("get-goodShelveInfo", this.tableKey, this.goodsShelvesList);
      this.orderSelectedRowKeys = [];
    },

    handleCancel() {
      this.$emit("close-goodShelveInfo");
    },
  },
};
</script>

<style lang="less" scoped>
</style>
